/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.bff.designtime.generator.core;

import com.inspur.edp.bff.designtime.generator.VmGeneratorContext;
import com.inspur.edp.bff.designtime.generator.core.rtgen.datagenerator.FSDataGeneratorContext;
import com.inspur.edp.bff.designtime.generator.core.rtgen.managergenerator.FSMgrGeneratorContext;
import com.inspur.edp.bff.designtime.generator.core.rtgen.typeinfo.FSIntermediateTypeInfo;
import com.inspur.edp.cef.entity.dependenceTemp.DataValidator;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.coreGenerator.entityGenerator.CommonModelCoreGeneratorContext;
import com.inspur.edp.cef.variable.dtgenerator.VariableGeneratorContext;
import com.inspur.edp.cef.variable.dtgenerator.core.VariableCoreGenCtx;
import com.inspur.edp.das.commonmodel.IGspCommonModel;
import com.inspur.edp.formserver.viewmodel.GspViewModel;

import java.util.ArrayList;

public class VmCoreGenContext extends CommonModelCoreGeneratorContext {

  private VmGeneratorContext privateVmGenContext;
  private MediateType privateVmMgrImplType;
  private MediateType privateExtendActionConfigType;
  private MediateType privateSouceConfigType;
  private MediateType defaultQueryConditionType;
  //  private Assembly privateAssembly;
  private String privateVarConfigAttrStr;
  private FSIntermediateTypeInfo fsIntermediateTypeInfo = new FSIntermediateTypeInfo();
  private FSDataGeneratorContext dataGeneratorContext;
  private ArrayList<MediateType> extendProviders = new ArrayList<>();
  private String viewModelChangesetName;
  private String changeConvertorName;
//  private java.util.HashMap<String, Assembly> copiedAssembly = new java.util.HashMap<String, Assembly>();

  public VmCoreGenContext(VmGeneratorContext cmGenCtx, IGspCommonModel commonModel) {
    super(cmGenCtx, commonModel);
    setVmGenContext(cmGenCtx);
  }

  public final VmGeneratorContext getVmGenContext() {
    return privateVmGenContext;
  }

  public final void setVmGenContext(VmGeneratorContext value) {
    privateVmGenContext = value;
  }

  public final MediateType getVmMgrImplType() {
    return privateVmMgrImplType;
  }

  public final void setVmMgrImplType(MediateType value) {
    privateVmMgrImplType = value;
  }

  public final MediateType getExtendActionConfigType() {
    return privateExtendActionConfigType;
  }

  public final void setExtendActionConfigType(MediateType value) {
    privateExtendActionConfigType = value;
  }

  public final MediateType getSouceConfigType() {
    return privateSouceConfigType;
  }

  public final void setSouceConfigType(MediateType value) {
    privateSouceConfigType = value;
  }

  public MediateType getDefaultQueryConditionType() {
    return defaultQueryConditionType;
  }

  public void setDefaultQueryConditionType(
      MediateType defaultQueryConditionType) {
    this.defaultQueryConditionType = defaultQueryConditionType;
  }

  public final String getVarConfigAttrStr() {
    return privateVarConfigAttrStr;
  }

  public final void setVarConfigAttrStr(String value) {
    privateVarConfigAttrStr = value;
  }

  public final java.lang.Class getCustomActionType(String assemblyName, String className,
      String compId) throws ClassNotFoundException {
    DataValidator.checkForEmptyString(assemblyName, "assemblyName");
    DataValidator.checkForEmptyString(className, "className");

    Class c = Class.forName(className);
    if (c == null) {
      throw new RuntimeException("加载构件程序集" + assemblyName + "失败。");
    }
    return c;
  }

  private java.lang.Class getTypeFromAssembly(String className) throws ClassNotFoundException {
    Class c = Class.forName(className);
    if (c == null) {
      throw new RuntimeException("加载构件程序集失败。");
    }
    return c;
  }

  private MediateType rootPropMapperType;

  public MediateType getRootEntityPropMapperType() {
    return rootPropMapperType;
  }

  public void setRootEntityPropMapperType(MediateType mediateType) {
    rootPropMapperType = mediateType;
  }

  public Boolean getEnableStdDateTime() {
    return ((GspViewModel) getCommonModel()).getEnableStdTimeFormat();
  }

  @Override
  public String getVersionControlPropertyName() {
    return null;
  }

  private FSMgrGeneratorContext mgrContext;

  public FSMgrGeneratorContext getMgrContext() {
    return mgrContext;
  }

  public void setMgrContext(FSMgrGeneratorContext mgrContext) {
    this.mgrContext = mgrContext;
  }

  public FSIntermediateTypeInfo getFsIntermediateTypeInfo() {
    return fsIntermediateTypeInfo;
  }

  public FSDataGeneratorContext getDataGeneratorContext() {
    return dataGeneratorContext;
  }

  public void setDataGeneratorContext(FSDataGeneratorContext dataGeneratorContext) {
    this.dataGeneratorContext = dataGeneratorContext;
  }

  public ArrayList<MediateType> getExtendProviders() {
    return extendProviders;
  }

  public String getViewModelChangesetName() {
    return viewModelChangesetName;
  }

  public void setViewModelChangesetName(String viewModelChangesetName) {
    this.viewModelChangesetName = viewModelChangesetName;
  }

  public String getChangeConvertorName() {
    return changeConvertorName;
  }

  public void setChangeConvertorName(String changeConvertorName) {
    this.changeConvertorName = changeConvertorName;
  }

}
